﻿using PBMessage;
using UnityEngine;
using System.Collections;

public class UIMainView : BaseWidget
{
	public GameObject Btn_EnterMatchBattle;
    public GameObject Btn_CancelMatch;
    public GameObject MatchingG;
	public UILabel UserNameLabel;
	public override void OnLoad()
	{
		Init();
	}
	
	public void Init()
	{
		UIEventListener.Get(Btn_EnterMatchBattle).onClick = Click_EnterMatchBattle;
        UIEventListener.Get(Btn_CancelMatch).onClick = this.Click_CancelMatch;
		UserNameLabel.text = Game.Model.Get<PlayerModel>().NickName;
	}

	public void Click_EnterMatchBattle(GameObject go)
	{
		Game.Packet.SendMatchBattle();
	}

	public void Server_MatchBattle(SC_EnterReadyRoom data)
	{
		Game.Battle.MatchBattleReadyInfo = data;
		Game.UI.Close("MainView");
		Game.UI.Show("MatchBattle");
	}

    public void ServerRet_MatchGame(SC_RetMatchGame retMatch)
    {
        this.MatchingG.SetActive(true);
        this.Btn_EnterMatchBattle.SetActive(false);
    }

    public void ServerRet_Cancel(SC_RetCancelMatch retData)
    {
        this.MatchingG.SetActive(false);
        this.Btn_EnterMatchBattle.SetActive(true);
    }

    public void Click_CancelMatch(GameObject go)
    {
        CS_CancelMatch cancelMatch = new CS_CancelMatch();
        cancelMatch.UserId = Game.Model.Get<PlayerModel>().UserId;
        Game.Net.SendPacket<CS_CancelMatch>(cancelMatch,PBMessageID.CS_CancelMatch);
    }
}
